<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>xmake</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="//cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/package/system_package">https://xmake.io/#/package/system_package</a>
</br>
    <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
<style>
#carbonads {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#carbonads {
  display: flex;
  max-width: 330px;
  background-color: hsl(0, 0%, 98%);
  box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
}

#carbonads a {
  color: inherit;
  text-decoration: none;
}

#carbonads a:hover {
  color: inherit;
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

#carbonads .carbon-wrap {
  display: flex;
}

.carbon-img {
  display: block;
  margin: 0;
  line-height: 1;
}

.carbon-img img {
  display: block;
}

.carbon-text {
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
  text-align: left;
}

.carbon-poweredby {
  display: block;
  padding: 8px 10px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
}
</style>
    <h2 id="findsystempackage">Find System Package</h2>
<p>If you feel that the above built-in package management method is very inconvenient, you can use the built-in interface <code>find_packages</code> provided by xmake.</p>
<p>And through the system and third-party package management tools for the installation of the dependency package, and then integrated with xmake, for example, we look for an openssl package:</p>
<pre><code class="lang-lua">local packages = find_packages("openssl", "zlib")
</code></pre>
<p>The returned results are as follows:</p>
<pre><code class="lang-lua">{
    {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}},
    {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}
}
</code></pre>
<p>If the search is successful, return a table containing all the package information, if it fails, return nil</p>
<p>The return result here can be directly passed as the parameter of <code>target:add</code>, <code>option:add</code>, which is used to dynamically increase the configuration of <code>target/option</code>:</p>
<pre><code class="lang-lua">option("zlib")
    set_showmenu(true)
    before_check(function (option)
        option:add(find_packages("openssl", "zlib"))
    end)
</code></pre>
<pre><code class="lang-lua">target("test")
    on_load(function (target)
        target:add(find_packages("openssl", "zlib"))
    end)
</code></pre>
<p>Currently this interface supports the following package management support:</p>
<ul>
<li>conan</li>
<li>vcpkg</li>
<li>homebrew</li>
<li>pkg-config</li>
</ul>
<p>If third-party tools such as <code>homebrew</code>, <code>pkg-config</code> are installed on the system, then this interface will try to use them to improve the search results.</p>
<p>For a more complete description of the usage, please refer to the <a href="/mirror/manual/builtin_modules.html#find_packages">find_packages</a> interface documentation.</p>
<p>Of course, if you feel that integrating third-party dependencies by looking for packages is not enough, you can also directly integrate remote dependencies through <code>add_requires</code>.<br>For details, see the documentation: <a href="/mirror/package/remote_package.html">Using Remote Dependencies</a></p>
<h2 id="findhomebrewpackage">Find homebrew package</h2>
<p>Alternatively, we can also find the package from the manually specified package manager:</p>
<pre><code class="lang-lua">find_packages("brew::pcre2/libpcre2-8", "brew::x264")
</code></pre>
<p>We only need to add the <code>brew::</code> prefix, you can explicitly specify the package source from homebrew to find the package, if there are multiple pkgconfig files in <code>brew::pcre2</code>, for example: libpcre2-8.pc, libpcre2-16. Pc, libpcre2-32.pc</p>
<p>Then we can use <code>brew::pcre2/libpcre2-16</code> to select the link library information specified by the corresponding pkgconfig file.</p>
<p>Since homebrew is generally installed directly into the system, users do not need to do any integration work, <code>find_packages</code> has been natively seamlessly supported.</p>
<h2 id="findvcpkgpackage">Find vcpkg package</h2>
<p>Currently xmake v2.2.2 version has already supported vcpkg, users only need to install vcpkg, execute <code>$ vcpkg integrate install</code>, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread.</p>
<p>Of course, we can also manually specify the root path of vcpkg to support:</p>
<pre><code class="lang-console">$ xmake f --vcpkg=f:\vcpkg
</code></pre>
<p>Or we can set it to the global configuration to avoid repeating the settings each time the configuration is switched:</p>
<pre><code class="lang-console">$ xmake g --vcpkg=f:\vcpkg
</code></pre>
<p>Then, we can specify the dependency package in vcpkg by using the <code>vcpkg::</code> prefix:</p>
<pre><code class="lang-lua">find_packages("vcpkg::zlib", "vcpkg::openssl")
</code></pre>
<h2 id="findtheconanpackage">Find the conan package</h2>
<p>Xmake v2.2.6 and later versions also support finding the specified package from the conan:</p>
<pre><code class="lang-lua">find_packages("conan::openssl/1.1.1g")
</code></pre>
<h2 id="testcommandforfindingpackage">Test command for finding package</h2>
<p>We can use the following command to quickly detect the package information specified on the system:</p>
<pre><code class="lang-console">$ xmake l find_packages x264
{
   {
     Links = {
       "x264"
     },
     Linkdirs = {
       "/usr/local/Cellar/x264/r2699/lib"
     },
     Version = "0.148.2699 a5e06b9",
     Includeirs = {
       "/usr/local/Cellar/x264/r2699/include"
     }
   }
}
</code></pre>
<p>We can also add a third-party package manager prefix to test:</p>
<pre><code class="lang-console">xmake l find_packages conan::OpenSSL/1.0.2n@conan/stable
</code></pre>
<p>!> It should be noted that if the find_package command is executed in the project directory with xmake.lua, there will be a cache. If the search fails, the next lookup will also use the cached result. If you want to force a retest every time, Please switch to the non-project directory to execute the above command.</p>
</article>
</body>
</html>